let {PORT}=require('./config/config.default.js')
let path=require('path')
let koa=require('koa')
let koaBody=require('koa-body')
let KoaStatic=require('koa-static')
let parameter=require('koa-parameter')
let router=require('./router/index.js')
let app=new koa()

app.use(koaBody({
    multipart:true,  //上传文件
    formidable:{
        uploadDir:path.join(__dirname,'./public/upload'),
        keepExtensions:true,//保存后缀名
    }
}))

app.use(KoaStatic(path.join(__dirname,'./public/static')))  //获取静态资源

app.use(parameter(app))


app.use(router.routes()).use(router.allowedMethods())

app.on('error',(err,ctx)=>{
    ctx.status=400
    ctx.body=err
})
app.listen(PORT,()=>{
    console.log(PORT+'端口已开启')
})

